package com.example.docmanagement.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

/**
 * 权限实体类，对应 permissions 表
 */
@Entity
@Table(name = "permissions")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EntityListeners(AuditingEntityListener.class)
public class Permission {

    /**
     * 权限 ID（自增主键）
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 权限唯一标识，如 user:list
     */
    @Column(nullable = false, unique = true, length = 100)
    private String name;

    /**
     * 权限显示名称，如 用户列表
     */
    @Column(name = "display_name", nullable = false, length = 100)
    private String displayName;

    /**
     * 权限描述
     */
    @Column(columnDefinition = "TEXT")
    private String description;

    /**
     * 资源模块，如 user、role
     */
    @Column(nullable = false, length = 50)
    private String resource;

    /**
     * 操作类型，如 list、view、create
     */
    @Column(nullable = false, length = 50)
    private String action;

    /**
     * 权限分类（业务自定义）
     */
    @Column(length = 50)
    private String category;

    /**
     * 排序字段
     */
    @Builder.Default
    @Column(name = "sort_order")
    private Integer sortOrder = 0;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "created_at", nullable = false, updatable = false)
    private LocalDateTime createdAt;
}


